<?php
namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller{
    public function index(){
        $this->display();
    }

    public function verify(){
        ob_end_clean();
        $verify = new \Think\Verify();
        $verify->entry();
    }

    public function Login(){
        if (!$_POST) halt("页面不存在");
        if(IS_POST){
            if (check_verify($verify)){
                $this->error('验证码输入错误');
            }

            $username = $_POST['username'];
            $password = $_POST['password'];
            $result = D("manager") ->where("username = '$username' and password = '$password'") ->select();
            if ($result){
                $_SESSION['username'] = $username;
                $this->success("登陆成功","Index/index");
            }else{
                $this->success("登录失败,","Login/index");
            }
        }
        //halt是抛出异常，告诉你发生错误的文件名，第几行，给程序员看的。$this->error是给用户看的，比如登陆时密码不正确就用$this->error.

    }
    public function queit(){
        unset($_SESSION['username']);
        $this->display('Login/index');
    }

    }